export default {

    data() {
        return {
            eventList: [{
                value: "S_CANCEL",
                classStyle: "s",
                tip: "取消订单(未支付)",
                function: (r) => {
                    this.cancelOrder(r, 0);
                }
            },
            {
                value: "S_MODIFY_AMOUNT",
                classStyle: "s",
                tip: "修改价格",
                function: (r) => {
                    this.modifyAmount(r);
                }
            },
            {
                value: "S_MODIFY_ADDRESS",
                classStyle: "s",
                tip: "修改收货地址",
                function: (r) => {
                    this.updateAddress(r);
                }
            },
            {
                value: "S_NOTE",
                classStyle: "s",
                tip: "订单备注",
                function: (r) => {
                    this.noteOrder(r);
                }
            },
            {
                value: "S_DELIVERY",
                classStyle: "m",
                tip: "商家发货",
                function: (r) => {
                    this.OrderDelivery(r, 0);
                }
            },
            {
                value: "S_MODIFY_LOGISTICS",
                classStyle: "s",
                tip: "修改物流",
                function: (r) => {
                    this.OrderDelivery(r, 1);
                }
            },
            // {
            //     value: "S_0007",
            //     classStyle: "s",
            //     tip: "取消订单(已支付)",
            //     function: (r) => {
            //         this.cancelOrder(r, 1);
            //     }
            // },
            // 售后订单
            {
                value: "S_R_AGREE",
                classStyle: "s",
                tip: "同意",
                function: (r) => {
                    this.refundAgree(r);
                }
            },
            {
                value: "S_R_REFUSE",
                classStyle: "s",
                tip: "拒绝",
                function: (r) => {
                    this.refundRefuse(r);
                }
            },
            {
                value: "S_R_CONFIRM_REFUND",
                classStyle: "s",
                tip: "确认退款",
                function: (r) => {
                    this.refundConfirm(r);
                }
            },
            {
                value: "S_R_NOTE",
                classStyle: "s",
                tip: "备注",
                function: (r) => {
                    this.noteRefund(r);
                }
            },
            ],
        };
    },

    methods: {
        // 退货订单备注
        async noteRefund(r) {
            // 打开加载遮罩层
            this.$vFN.Tools.setLoad(true);
            let _d = await import("@/directives/OrderRefundNote/index");
            // 关闭加载遮罩层
            this.$vFN.Tools.setLoad(false);
            _d.default.init({
                item: r,
                onSuccess: (r) => {
                    this.mixinTable_refreshData();
                },
            })
        },
        // 同意退货
        async refundAgree(r) {
            // 打开加载遮罩层
            this.$vFN.Tools.setLoad(true);
            let _d = await import("@/directives/OrderRefundAgree/index");
            // 关闭加载遮罩层
            this.$vFN.Tools.setLoad(false);
            _d.default.init({
                item: r,
                onSuccess: (r) => {
                    this.mixinTable_refreshData();
                },
            })
        },

        // 拒绝退货
        async refundRefuse(r) {
            // 打开加载遮罩层
            this.$vFN.Tools.setLoad(true);
            let _d = await import("@/directives/OrderRefundRefuse/index");
            // 关闭加载遮罩层
            this.$vFN.Tools.setLoad(false);
            _d.default.init({
                item: r,
                onSuccess: (r) => {
                    this.mixinTable_refreshData();
                },
            })
        },
        // 确定退款 确定售后收货
        async refundConfirm(r) {


            this.$confirm("确定此操作么", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                // type: "error",
                dangerouslyUseHTMLString: true,
            }).then(async () => {
                console.log(111);

                let _data = await this.$vFN.Http.post({
                    url: "mall-site-portal/order-rights/confirmRefundOrderRights",
                    data: {
                        orderRightsId: r.id
                    }
                }, window);

                if (_data._ok) {
                    this.$vFN.Tools.messageSuccess("操作成功");
                    this.editBoxClose();
                    this.onSuccess();
                    this.mixinTable_refreshData();
                }
            })
                .catch(() => { });

        },
        // 取消订单 type:0未支付，1待发货
        async cancelOrder(r, type) {
            // 打开加载遮罩层
            this.$vFN.Tools.setLoad(true);
            let _d = await import("@/directives/OrderCancel/index");
            // 关闭加载遮罩层
            this.$vFN.Tools.setLoad(false);
            _d.default.init({
                item: r,
                type: type,
                onSuccess: (r) => {
                    this.mixinTable_refreshData();
                },
            })
        },
        // 商家发货 type=0 修改物流 type=1
        async OrderDelivery(r, type) {
            // 打开加载遮罩层
            this.$vFN.Tools.setLoad(true);
            let _d = await import("@/directives/OrderDelivery/index");
            // 关闭加载遮罩层
            this.$vFN.Tools.setLoad(false);
            _d.default.init({
                item: r,
                type: type,
                onSuccess: (r) => {
                    this.mixinTable_refreshData();
                },
            })
        },
        // 修改价格
        async modifyAmount(r, type) {
            // 打开加载遮罩层
            this.$vFN.Tools.setLoad(true);
            let _d = await import("@/directives/OrderModifyAmount/index");
            // 关闭加载遮罩层
            this.$vFN.Tools.setLoad(false);
            _d.default.init({
                item: r,
                onSuccess: (r) => {
                    this.mixinTable_refreshData();
                },
            })
        },
        // 订单备注
        async noteOrder(r) {
            // 打开加载遮罩层
            this.$vFN.Tools.setLoad(true);
            let _d = await import("@/directives/OrderNote/index");
            // 关闭加载遮罩层
            this.$vFN.Tools.setLoad(false);
            _d.default.init({
                item: r,
                onSuccess: (r) => {
                    this.mixinTable_refreshData();
                },
            })
        },
        // 修改收货地址
        async updateAddress(r) {
            // 打开加载遮罩层
            this.$vFN.Tools.setLoad(true);
            let _d = await import("@/directives/OrderUpdateAddress/index");
            // 关闭加载遮罩层
            this.$vFN.Tools.setLoad(false);
            _d.default.init({
                item: r,
                onSuccess: (r) => {
                    this.mixinTable_refreshData();
                },
            })
        },
        // 获取订单详情
        async getOrderDetail(id_) {
            let _data = await this.$vFN.Http.post({
                url: "admin/order/getOrderItem",
                data: {
                    orderId: id_
                },
            }, window);
            if (_data._ok) {
                return _data.data
            } else {
                return false
            }
        },

        // 获取售后的订单详情
        async getOrderRefundDetail(id_) {
            let _data = await this.$vFN.Http.post({
                domain: "APP_MAIN_DOMAIN",
                url: "mall-site-portal/order-rights/getItem",
                data: {
                    orderRightsId: id_
                },
            }, window);
            if (_data._ok) {
                return _data.data
            } else {
                return false
            }
        },

        // 订单事件类型方法
        async orderEventClick(_arr) {
            let item_ = _arr[0], iitem_= _arr[1],type_ = _arr[2];
            let _data = null;
            if(type_=="refund"){
                _data = await this.getOrderRefundDetail(item_.id)
            }
            else{
                _data = await this.getOrderDetail(item_.id)
            }
            if (_data) {
                this.toEventData(iitem_).function(_data);
            }
        },
        // 退货订单事件类型方法
        async orderRefundEventClick(item_, iitem_) {
            let _data = await this.getOrderRefundDetail(item_.id);
            if (_data) {
                this.toEventData(iitem_).function(_data);
            }
            // console.log("7788", this.toEventData(iitem_));
        },

        // 全部订单的订单详情
        async OrderDetailsCilck(item_) {

            let _data = await this.getOrderDetail(item_.id)
            this.OrderDetails(_data)

        },
        // 售后订单的订单详情
        async OrderRefundDetailCilck(item_) {

            let _data = await this.getOrderRefundDetail(item_.id)
            this.RefundDetails(_data)

        },
        // 订单详情 弹窗
        async OrderDetails(r) {
            // 打开加载遮罩层
            this.$vFN.Tools.setLoad(true);
            let _d = await import("@/directives/OrderDetails/index");
            // 关闭加载遮罩层
            this.$vFN.Tools.setLoad(false);
            _d.default.init({
                item: r,
                onSuccess: (r) => {
                    this.mixinTable_refreshData();
                },
            })
        },

        // 售后订单详情 弹窗
        async RefundDetails(r) {
            // 打开加载遮罩层
            this.$vFN.Tools.setLoad(true);
            let _d = await import("@/directives/RefundDetails/index");
            // 关闭加载遮罩层
            this.$vFN.Tools.setLoad(false);
            _d.default.init({
                item: r,
                onSuccess: (r) => {
                    this.mixinTable_refreshData();
                },
            })

        },

        // 根据订单事件类型 添加样式class
        toEventData(item_) {
            let _val = null;
            this.eventList.forEach(item => {
                if (item.value == item_.eventValue) {
                    _val = item
                }
            })
            return _val
        },

        // 售后状态转换文字
        refundStatus(number) {
            let text;
            switch (number) {
                case 1:
                    text = "可售后"
                    break;
                case 2:
                    text = "售后中"
                    break;
                case 3:
                    text = "已售后"
                    break;
                case 4:
                    text = "关闭售后"
                    break;
                default:
                    text = "无";
            }
            return text
        },

        // 支付方式转换文字
        payManner(object) {

            let text;
            if (!this.$vFN.Utils.isEmpty(object) && !this.$vFN.Utils.isEmpty(object.payType)) {
                switch (object.payType) {
                    case 1:
                        text = "货到付款"
                        break;
                    case 2:
                        text = "余额支付"
                        break;
                    case 3:
                        text = "微信支付"
                        break;
                    default:
                        text = "无";
                }
            } else {
                text = "无";
            }

            return text
        },

        // 收货地址拼接文字
        addressName(object) {
            let text;
            if (!this.$vFN.Utils.isEmpty(object)) {
                text = `${object.province}${object.city}${object.region}${object.detailAddress}${object.street}`
            } else {
                text = "无"
            }

            return text
        },

        // 送货方式转换文字
        deliveryWay(number) {
            let text;
            switch (number) {
                case 1:
                    text = "无需物流"
                    break;
                case 2:
                    text = "商家配送"
                    break;
                case 3:
                    text = "到店自提"
                    break;
                default:
                    text = "无";
            }

            return text
        },

    },
};